home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1994 October / Macformat17.cdr / Shareware City / Developers / demoCdef ƒ / About CDEF's next >
Encoding:
Text File  |  1994-06-16  |  13.7 KB  |  321 lines  |  [TEXT/KAHL]

  1. /*---------------------------------------------------------------------
  2. Here is a collection of 9 CDEF's (Control Definitions) and some other
  3. bits of source code to demo their use.
  4.  
  5. This stuff is also pretty much un-documented - this file and comments
  6. in the source is about it.  I've learned to appreciate the job that
  7. Tech Writers do - I've started some "real" documentation, but it
  8. never seems complete.  
  9.  
  10. Read the source code - especially the .r file - it might help you
  11. understand how to use these CDEF's.
  12.  
  13. There are no restrictions on this (as far as I know and care), use it
  14. if you wish.  If you find some use for this code, I'd love to know 
  15. about it.
  16.  
  17. This code is absolutely unwarranted.  I'm sure that there are some
  18. errors somewhere, but it does seem to work.  I'm uploading this
  19. because when I was learning (I still am…) how to program on the Mac,
  20. I learned a lot from source code that others uploaded.  Hopefully, 
  21. this will help someone else learn something about the Mac.
  22.  
  23. The source code for the actual CDEF's is not included here, but you
  24. can find the CDEF's as code resources in file xDEF.rsrc.  I'd like
  25. to see the CDEF's "shaken out" a bit before I upload the source - if
  26. anyone wants it.  Just let me know if I should upload it.
  27.  
  28. Jim Stout
  29.  
  30. CompuServe  : 73240,2052
  31. AppleLink   : WRQ
  32. AOL         : JasG
  33. Internet    : JimS@WRQ.COM
  34. -----------------------------------------------------------------------
  35.  
  36. A few weeks back I was reading the Human Interface volume of Inside Mac
  37. and it struck me as funny that Apple refers to various controls (used
  38. throughout the MacOS) as "not supported by the Toolbox".  Controls like
  39. "little arrow" controls used to set Date & Time, Memory etc. ,"Slider 
  40. Controls" like those in the Sound or Brightness control panels and a
  41. "Progress Bar" are simply are not to be found in the Toolbox.
  42.  
  43. Apple simulates controls by displaying appropriate PICT's and handling
  44. mouse events in a dialog filter (I think).
  45.  
  46. I realized that over the past couple of years, I had written some of
  47. those controls (the rest are hot off my coding pad).
  48.  
  49. One of the CDEF's, 104 "Tog Button" is a little different.  This is
  50. explained below in the section "About Tog Buttons".  You can also
  51. get this type of control with variation code 4 and the 3D Buttons
  52. CDEF.
  53.  
  54. All of these controls will work with System 6 or System 7 - the only
  55. caveat is that the PopUpMenu control requires PopUpMenuSelect.  I have
  56. tested them on machines from a MacPlus through a PowerMac 7100.
  57. (Actually, I've tested these as far back as System 3.2 - I've gotta
  58. do something with that original 128k Mac with MacPlus ROM's that 
  59. is sitting in the corner...)
  60.  
  61. If possible, all except the GroupBox and PopUpMenu controls will
  62. use 32bit ColorQuickdraw and offscreen GWorlds to support color.
  63. As far as I can tell, they all handle low memory situations by
  64. refusing to draw themselves.  Let me know if you see any problems.
  65.  
  66. All controls with titles honor the "useWindFont" variation code (to
  67. draw in a non-System font), will properly color themselves if a 'cctb'
  68. resource is present and when  disabled, will appear in the proper
  69. System 7 style gray (if possible).
  70.  
  71. I have not written these to support non-roman script systems.
  72.  
  73. Other variation codes, sizes and non-standard control template values
  74. are listed below.
  75.  
  76. -----------------------------------------------------------------------
  77.  
  78. The controls are:
  79.  
  80. procID    Name            Function
  81. ------    -----------        ------------------------------------------
  82. 100        GroupBox        draws a titled box, text in upperleft
  83. 101        PopUp Menu        system 7 style popup menu control
  84. 102        Spinner            "little arrows" control
  85. 103        Date & Time        Date & Time control using "little arrows"
  86. 104        Tog Button        a new type of "one or many" control
  87. 105        HSlider            horizontal slider control
  88. 106        VSlider            vertical slider control
  89. 107        3D Buttons        a 3d replacement for the standard button CDEF
  90. 108        Progress Bar    a progress bar CDEF
  91.  
  92. Variation codes & size (min h & w is minimum required height & width for the
  93. ======================    control rect when using Chicago 12 font)
  94.  
  95. CDEF        varCode        min h & w    Result
  96. ---------    ----------    ----------    ---------------------------------------------
  97. GroupBox    0                        Draws a solid frame
  98.             1                        Draws a dotted frame
  99.             2                        * not used *
  100.             4                        * not used *
  101.             8                        Use the Window font for title
  102.             
  103.             NOTE: To avoid problems with "layering" of this control over or
  104.             under the contents of a box, set the height of this control to 16 or
  105.             so, then put the height you REALLY want in the RefCon of the CNTL
  106.             template.  The control rect (used by the Dialog Manager) will not
  107.             obstruct other controls.  However, when the control draws - it will
  108.             use the height value from the control RefCon.
  109. ---------------------------------------------------------------------------------            
  110. PopUp Menu                19 x nn        (see IM VI or other docs for Apple CDEF 63
  111.                         19 x 25        for "triangle only" menu
  112.                         
  113.                         NOTE: if the menu has styled text items, the height may
  114.                                 need to be greater than 19.
  115.                         Unlike the Apple CDEF 63, this control will:
  116.                                 - behave the same with System 6 & 7
  117.                                 - properly handle colored menus
  118.                         It DOES NOT support:
  119.                                 - Icons or cmd keys
  120.                                 - Styled text titles
  121. ---------------------------------------------------------------------------------    
  122.  
  123. Spinner        0            18 x nn        Draw small arrows, as in the "Date & Time" Control panel
  124.             1            25 x nn        Draw large arrows, as in the "Memory" Control panel
  125.             2                        * not used *
  126.             4                        * not used *
  127.             8                        Use the Window font for control value
  128.             
  129.                         NOTE: use 18 x 11 or 25 x 15 to get arrows only
  130. ---------------------------------------------------------------------------------    
  131.  
  132. Date & Time    0            18 x 160    Show both, date left, time right, justified    
  133.             1            18 x 80        Show date only, left justified in control rect    
  134.             2            18 x 80        Show time only, left justified in control rect    
  135.             4            37 x 80        Show both on 2 lines, date over time
  136.             8                        Use the Window font for control value
  137.                         
  138.                         NOTE: funny date or time separator characters may need larger
  139.                                 rect.
  140. ---------------------------------------------------------------------------------    
  141.                                 
  142. Tog Button    0            18 x nn        Normal button title
  143.             1                        * not used *
  144.             2                        * not used *
  145.             4                        * not used *
  146.             8                        Use the Window font for title
  147. ---------------------------------------------------------------------------------    
  148.                         
  149. HSlider        0            24 x 121    Looks exactly like the "Brightness" Control panel
  150.             1                        "Thumb" is drawn in gray pattern
  151.             2                        Scale portion is drawn in bg color (not filled)
  152.             4                        Scale portion is drawn in gray pattern
  153.             8                        * not used *
  154. ---------------------------------------------------------------------------------    
  155.  
  156. VSlider        0            105 x 24    Looks exactly like the "Sound" Control panel
  157.             1                        "Thumb" is drawn in gray pattern
  158.             2                        Scale portion is drawn in bg color (not filled)
  159.             4                        "Thumb" will not "snap" to tick mark
  160.             8                        Scale is blank, no numbers, no tick marks
  161.             
  162.                         NOTE: ht is 12*divisions + 21 (see below)
  163. ---------------------------------------------------------------------------------    
  164.  
  165. 3D Buttons    0            any x any    draws a push button
  166.             1                        draws a checkbox
  167.             2                        draws a radiobutton
  168.             4                        draws a Tog Button control
  169.             8                        Use the Window font for title
  170.             
  171.             This control should behave just like the standard CDEF 0 when running
  172.             in 1 bit (B&W) mode OR if the background is white.  If running on a
  173.             non-white background, this CDEF will draw "3 D" controls.  Colors are
  174.             taken from a 'cctb' resource.
  175. ---------------------------------------------------------------------------------    
  176.  
  177. Progress Bar 0            any x any    draws a horizontal progress bar
  178.              1                        draws a vertical progress bar
  179.              2                        draws a rounded, 3D progress bar
  180.              4                        not used
  181.              8                        not used
  182. ---------------------------------------------------------------------------------    
  183.                         
  184.                         
  185. All control drawing is clipped to the control rect, so it should be pretty obvious if
  186. you have a control rect that is too small.
  187.  
  188. Non-standard control template usage
  189. ===================================
  190.  
  191. GroupBox                does not use min, max, value or rfCon
  192.  
  193. PopUp Menu                (see Inside Mac VI or other docs for Apple CDEF 63)
  194.                         Does NOT support menu icons or cmd-keys, the menu
  195.                         can have them, but the control will not draw them.
  196.  
  197. Spinner                    standard use of min, max and value.
  198.                         the control refCon field can be a DITL item number for an
  199.                         editText item to update with the control value.
  200.                         
  201. Date & Time                does not use min, max
  202.                         contrlValue indicates hilited digits
  203.                                 1    hours
  204.                                 2    minutes
  205.                                 3    AM/PM
  206.                                 6    month  (6,7,8 match user order from Control Panel
  207.                                 7    day            and may not have these meanings)
  208.                                 8    year
  209.                                     
  210.                         contrlRfCon is seconds as passed to GetDateTime(), Secs2Date() 
  211.                         and Date2Secs() calls.  This is the "value" that the control
  212.                         adjusts.  Use GetCRefCon() to retrieve the "date time" value
  213.                         and SetCRefCon() to set it.
  214.                         
  215. HSlider                    min = 0, max = 100 - these are set by the control.
  216.                         value returned will range from min to max
  217.  
  218. VSlider                    refCon is used to indicate 'number of divisions' from 2-20.
  219.                         Default is 7 divisions with tick marks from 0-7.
  220.                         min = 0
  221.                         max = 12*"number of divisions"
  222.                         
  223.                         The value returned will range from min to max.
  224.                         
  225.                         The control "thumb" will "snap" to a tick mark.
  226.                         This means that the value will always be 12*tick mark.
  227.  
  228.                         To avoid the "snap" behavior, use varCode 4.
  229.                         
  230. 3D Buttons                standard use of all fields
  231. Progress Bar            standard use of all fields
  232.  
  233. -----------------------------------------------------------------------
  234. About "TogButtons" 
  235. -----------------------------------------------------------------------
  236. In early November 1991, I ran across an article in the October 1991
  237. "Apple Direct" by Bruce Tognazzini - Apple's human interface guru.  
  238. Each month Tog would write a column dealing with HI issues.  The article
  239. that caught my eye back then was titled "Case Study: One or more Buttons".  
  240.  
  241. I don't think that I can legally include Tog's article with this bit of
  242. code, but you can find it on many of the Apple Developer CD's in the 
  243.  
  244.     Periodicals:Apple Direct:Apple Direct Oct '91:Tog folder.  
  245.  
  246. It also is in his book "Tog on Interface" as chapter 36.
  247.  
  248. To summarize, Tog wrote about the design and usability testing of a new 
  249. interface element that he called "One or more Buttons" - essentially a
  250. control that was part Checkbox and part Radio button.  A group of
  251. Checkboxes can all be "Off" and a group of Radio buttons can only have
  252. one "On" value.  What was needed was a group that MUST have ONE "On"
  253. control but could have many "On" controls - a "One or more Button".
  254.  
  255. Tog's design for what I call "Tog Buttons" is a cross between a Radio
  256. button and a Checkbox.  The control is a diamond (a Checkbox rotated 90
  257. degrees) with a diamond shaped indicator (like the  circular indicator
  258. in a Radio button).  The behavior is also a cross between the two
  259. other controls.  If only one control is ON, then clicking on it turns
  260. that control OFF and turns on an adjacent control (just like a pair of
  261. radio buttons), if one or more of the controls is ON, then others can be
  262. toggled (just like a checkbox).
  263.  
  264. Another twist on the behavior is that if only one control is ON, a
  265. click on that control will turn if OFF, and turn on the one just
  266. above (or to the left of) it.  When the first (or last) control 
  267. is reached, the direction reverses, turning on the one just below 
  268. (or to the right).  Tog likened this behavior to that of a drop of 
  269. mercury when you press on it with a finger (but without the toxicity!).
  270.  
  271. The behavior is such that with a single ON button, clicking on just
  272. that button, causes it to "jump" up (or leftward).  If you keep
  273. chasing the single ON button, it will keep "jumping" up until it must
  274. reverse direction and start "jumping" down.  Unless you are "chasing"
  275. a button like this, when only one button is ON, the default behavior
  276. is to jump UP (or to the left).  To see this, try the TogDemo program
  277. and you will see what I mean.   
  278.  
  279. For some reason, this appealed to me as an interesting project and I
  280. spent a fun afternoon implementing Tog's idea.  I ended up creating a
  281. CDEF to implement the control described by Tog and a couple of routines
  282. in C to support the desired behavior of "Tog Buttons".
  283.  
  284. -----------------------------------------------------------------------
  285. How to use a Tog Button in a dialog
  286. ===================================
  287.  
  288. Obviously, using a Tog Button is only needed if you have a situation
  289. that has a group of items that requires "One or Many" values.  An
  290. example might be a search :
  291.  
  292.    - Search -----------------
  293.   |                          |
  294.   | <•> C files (.c)         |
  295.   | < > Include files (.h)   |
  296.   | < > Resource files (.r)  |
  297.   |                          |
  298.    --------------------------
  299.    
  300. The file cdefDemo.c shows how to use "Tog Buttons", but here is a
  301. brief list.
  302.  
  303. 1. Include the files TogLib.c/TogLib.h in your project.
  304. 2. Define the group of "Tog Buttons" in your dialog resource.
  305. 3. DITL item numbers MUST be successively numbered for
  306.    each group of "Tog Buttons".  This is IMPORTANT!
  307. 4. After calling GetNewDialog, but before calling ModalDialog, 
  308.    call initTogButtons() for each group of "Tog Buttons".
  309. 5. When a "Tog Button" is clicked, call setTogButtons() for
  310.    that group of "Tog Buttons".
  311. 6. When a non-Tog Button control is clicked, do whatever is
  312.    needed, then call resetTogButtons() for each group of 
  313.    "Tog Buttons".  This step simply insures that the next
  314.    click on a "Tog Button" will "go up".
  315. 7. Use regular calls to GetDItem() and GetCtlValue() to retrieve
  316.    the control values for "Tog Buttons".
  317.  
  318. The TogLib routines are the key to maintaining consistent behavior
  319. of the "Tog Buttons".  TogLib.h has a short description of each
  320. routine.
  321. ----------------------------------------------------------------------*/